﻿using FastCtr;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace test
{
    public partial class Form1 : Form
    {

        
        NewSerialPort myport = new NewSerialPort("myport");


        NewTCP myTCP = new NewTCP("mytcp");
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            
            Form form = new Form();
            form.Controls.Add(Class1.myudp);
            form.Show();
            
        }

        private void button2_Click(object sender, EventArgs e)
        {
            string[] strarr = Class1.myudp.SendBackMessageInstant("iio99990987hhhh", 5000);
            if (strarr == null)
            {
                MessageBox.Show("超时！");
            }
            else
            {
                MessageBox.Show(strarr[0] + "  " + strarr[1]);
            }




        }

        private void mycallback(string[] str)
        {
            MessageBox.Show(str[0] + "  " + str[1]);

        }
        


       
        private void button3_Click(object sender, EventArgs e)
        {
            Form form = new Form();
            form.Controls.Add(myport);
            form.Show();
        }

        private void button4_Click(object sender, EventArgs e)
        {
            string message = myport.SendBackMessageInstant("WOAINI A ", 5000);
            if (string.IsNullOrEmpty(message))
            {
                MessageBox.Show("choshi!");
            }
            else
            {
                MessageBox.Show(message);
            }

        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void button5_Click(object sender, EventArgs e)
        {
            Form form = new Form();
            form.Controls.Add(myTCP);
            form.ShowDialog();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {

        }

        private void button6_Click(object sender, EventArgs e)
        {
            while (true)
            {
                myTCP.Connect();
                myTCP.SendMessage("dddddddddddddddddddd");
                Thread.Sleep(500);
                myTCP.DisConnect();
                Thread.Sleep(500);
            }
        }

        private void button7_Click(object sender, EventArgs e)
        {
          string message=  myTCP.SendBackMessageInstant("ddddddf", 5000);
            if(message!=null)
            {
                Console.WriteLine(message);

            }
            else
            {
                Console.WriteLine("chaoshi");
            }
        }

    }
}
